package com.xms.web.framework.model;

import java.io.Serializable;

/**
 * <p>
 *  前端返回JSON对象
 * </p>
 *
 * @author migo
 * @since 2021-08-28
 */
public class JsonResultObject implements Serializable {
    public JsonResultObject()
    {
    }

    public JsonResultObject(Boolean isSuccess)
    {
        this.IsSuccess = isSuccess;
    }

    public JsonResultObject(Boolean isSuccess, Object data)
    {
        this.IsSuccess = isSuccess;
        this.Content = data;
    }

    public JsonResultObject(Boolean isSuccess, Object data, int statusCode)
    {
        this.IsSuccess = isSuccess;
        this.Content = data;
        this.StatusCode = statusCode;
    }

    public JsonResultObject(Boolean isSuccess, Object data, int statusCode, String errorMessage)
    {
        this.IsSuccess = isSuccess;
        this.Content = data;
        this.StatusCode = statusCode;
        this.ErrorMessage = errorMessage;
    }

    /// <summary>
    /// 是否成功
    /// </summary>
    public Boolean IsSuccess = true;

    /// <summary>
    /// 状态,success/error
    /// </summary>
    public String StatusName = null;

    /// <summary>
    /// 状态码
    /// </summary>
    public int StatusCode = 200;

    /// <summary>
    /// 内容
    /// </summary>
    public Object Content = null;

    /// <summary>
    /// 链接
    /// </summary>
    public String Url = null;

    /// <summary>
    /// 其它数据
    /// </summary>
    public Object Extra = null;

    /// <summary>
    /// 错误信息
    /// </summary>
    public String ErrorMessage = null;

    public static JsonResultObject failure(String message)
    {
        return new JsonResultObject(false, null, 500, message);
    }

    public static JsonResultObject failure(String message, int statusCode)
    {
        return new JsonResultObject(false, null, statusCode, message);
    }

    public static JsonResultObject failure(String message, int statusCode, Object data)
    {
        return new JsonResultObject(false, data, statusCode, message);
    }

    public static JsonResultObject failure(String message, Object data)
    {
        return new JsonResultObject(false, data, 400, message);
    }

    public static JsonResultObject success()
    {
        return new JsonResultObject(true, null, 200);
    }

    public static JsonResultObject success(Object data, int statusCode)
    {
        return new JsonResultObject(true, data, statusCode);
    }
    public static JsonResultObject success(String message, Object extra)
    {
        JsonResultObject result = new JsonResultObject();
        result.IsSuccess = true;
        result.Content = message;
        result.Extra = extra;
        return result;
    }

    public static JsonResultObject success(Object data)
    {
        return new JsonResultObject(true, data, 200);
    }
}
